home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / dvisun / dvisun.c < prev    next >
C/C++ Source or Header  |  1990-10-01  |  42KB  |  1,431 lines

  1. /**********************************************************************/
  2. /************************  Global Definitions  ************************/
  3. /**********************************************************************/
  4.  
  5. typedef int BOOLEAN;
  6. #define NEW(A) ((A *) malloc(sizeof(A)))
  7. #define DEBUG   1            /* for massive printing of input */
  8.                     /* trace information; select by -d */
  9.                     /* option after filename: */
  10.                     /* dvibit filename -d */
  11. #ifdef DEBUG
  12. int Debug = 0;
  13. #endif
  14. #define ALLOW_INTERRUPT    1        /* to allow ^C for Debugging */
  15.                     /* undefine for normal catch-^C mode */
  16.  
  17. #define BINARYOPEN fopen        /* byte-oriented host version */
  18.  
  19. #define ARITHRSHIFT 1                   /* define if ">>" operator is a
  20.                                            sign-propagating arithmetic
  21.                                            right shift */
  22. #define USEGLOBALMAG 1            /* when defined, the dvi global
  23.                           magnification is applied */
  24.  
  25. /* We leave USEGLOBALMAG undefined because there are only a very limited
  26.    number font magnifications  provided for  this program and  if it  is
  27.    defined, any dvi file is as likely as not to fail */
  28. /* ---fixme--- put something into the log file if it's not mag 1000 */
  29. #undef USEGLOBALMAG
  30.  
  31. #define  DVIFORMAT        2
  32. #define  FALSE            0
  33. #define  FIRSTPXLCHAR     0
  34. #ifndef FONTAREA
  35. #define  FONTAREA         "/usr/lib/dvifont/"
  36. #endif
  37. #define  LASTPXLCHAR    127
  38. #define  MAXOPEN         15  /* limit on number of open PXL files */
  39. #define  NPXLCHARS      128
  40. #define  PXLID         1001
  41. #define  READ             4  /* for access() */
  42. #define  RESOLUTION     118   /* is really 91.72192515 */
  43. #define  hconvRESOLUTION 118
  44. #define  vconvRESOLUTION 110
  45. #define  STACKSIZE      100
  46. #define  STRSIZE        257
  47. #define  TRUE             1
  48. #define  XSIZE         1024
  49. #define  YSIZE          800
  50.  
  51. /**********************************************************************/
  52. /***********************  external definitions  ***********************/
  53. /**********************************************************************/
  54.  
  55. #include "commands.h"
  56. #include <sgtty.h>
  57. #include <signal.h>
  58. #include <stdio.h>
  59. #include <pixrect/pixrect_hs.h>
  60. extern struct pixrect *pr_open();
  61. char *getenv();
  62. char *index();
  63. char *malloc();
  64. char *rindex();
  65. char *sprintf();
  66. char *strcpy();
  67.  
  68. int dummyInt;
  69. short dummyShort;
  70. char dummyChar;
  71.  
  72. /*-->NoSignExtend*/
  73. /**********************************************************************/
  74. /***************************  NoSignExtend  ***************************/
  75. /**********************************************************************/
  76.  
  77. int
  78. NoSignExtend(fp, n)    /* return n byte quantity from file fd */
  79. register FILE *fp;    /* file pointer    */
  80. register int n;        /* number of bytes */
  81.  
  82. {
  83.     register int x;    /* number being constructed */
  84.  
  85.     x = 0;
  86.     while (n--)  {
  87.     x <<= 8;
  88.     x |= getc(fp);
  89.     }
  90.     return(x);
  91. }
  92. /*-->SignExtend*/
  93. /**********************************************************************/
  94. /****************************  SignExtend  ****************************/
  95. /**********************************************************************/
  96.  
  97. int
  98. SignExtend(fp, n)   /* return n byte quantity from file fd */
  99. register FILE *fp;  /* file pointer    */
  100. register int n;     /* number of bytes */
  101.  
  102. {
  103.     int n1;         /* number of bytes        */
  104.     register int x; /* number being constructed */
  105.  
  106.     x = getc(fp);   /* get first (high-order) byte */
  107.     n1 = n--;
  108.     while (n--)  {
  109.     x <<= 8;
  110.     x |= getc(fp);
  111.     }
  112.  
  113.     /* NOTE: This code assumes that the right-shift is an arithmetic, rather
  114.     than logical, shift which will propagate the sign bit right.   According
  115.     to Kernighan and Ritchie, this is compiler dependent! */
  116.  
  117.     x<<=32-8*n1;
  118.     x>>=32-8*n1;  /* sign extend */
  119.  
  120. #ifdef DEBUG
  121.     if (Debug)
  122.     {
  123.     fprintf(stderr,"\tSignExtend(fp,%d)=%X\n",n1,x);
  124.     }
  125. #endif
  126.     return(x);
  127. }
  128. /**********************************************************************/
  129. /*************************  Global Procedures  ************************/
  130. /**********************************************************************/
  131.  
  132. /* Note: Global procedures are declared here in alphabetical order, with
  133.    those which do not return values typed "void".  Their bodies occur in
  134.    alphabetical order following the main() procedure.  The names are
  135.    kept unique in the first 6 characters for portability. */
  136.  
  137. void    AbortRun();
  138. float    ActualFactor();
  139. void    AllDone();
  140. FILE*    BINARYOPEN();
  141. void    Fatal();
  142. void    FindPostAmblePtr();
  143. void    GetBytes();
  144. void    GetFontDef();
  145. void    GotInterrupt();
  146. void    InitTerm();
  147. int    InputWaiting();
  148. void    LoadRast();
  149. void    MoveDown();
  150. void    MoveOver();
  151. void    OpenFontFile();
  152. int    PixRound();
  153. void    PutOut();
  154. int    ReadFontDef();
  155. void    ReadPostAmble();
  156. void    ResetTerm();
  157. void    SetChar();
  158. void    SetFntNum();
  159. void    SetRule();
  160. void    SkipFontDef();
  161. void    Warning();
  162.  
  163. /**********************************************************************/
  164. /*************************  Global Variables  *************************/
  165. /**********************************************************************/
  166.  
  167. int G_errenc = FALSE;       /* has an error been encountered?          */
  168. char G_Logname[STRSIZE];   /* name of log file, if created            */
  169. int G_interactive = TRUE;  /* is the program running interactively    */
  170.                            /* (i.e., standard output not redirected)? */
  171. int G_logging = 0;         /* Is a log file being created?            */
  172. struct sgttyb G_intty;     /* information about stdin if interactive  */
  173. FILE *G_logfp;             /* log file pointer (for errors)           */
  174. char G_progname[STRSIZE];  /* program name                            */
  175.  
  176. struct char_entry {        /* character entry */
  177.    unsigned short width, height;/* width and height in pixels */
  178.    short xOffset, yOffset;      /* x offset and y offset in pixels */
  179.    struct {
  180.        int isloaded;
  181.        union {
  182.        int fileOffset;
  183.        struct pixrect *pixrectptr;
  184.        } address;
  185.    } where;
  186.    int tfmw;            /* TFM width */
  187. };
  188.  
  189. struct font_entry {  /* font entry */
  190.    int k, c, s, d, a, l;
  191.    char n[STRSIZE];    /* FNT_DEF command parameters  */
  192.    int font_space;    /* computed from FNT_DEF s parameter        */
  193.    int font_mag;    /* computed from FNT_DEF s and d parameters */
  194.    char name[STRSIZE];    /* full name of PXL file                    */
  195.    FILE *font_file_id;  /* file identifier (0 if none)              */
  196.    int magnification;    /* magnification read from PXL file         */
  197.    int designsize;    /* design size read from PXL file           */
  198.    struct char_entry ch[NPXLCHARS];/* character information         */
  199.    struct font_entry *next;
  200. };
  201.  
  202. struct pixel_list
  203. {
  204.     FILE *pixel_file_id;        /* file identifier                          */
  205.     int use_count;              /* count of "opens"                         */
  206. };
  207.  
  208. int hconv, vconv;        /* converts DVI units to pixels             */
  209. int den;            /* denominator specified in preamble        */
  210. FILE *dvifp;            /* DVI file pointer                         */
  211. struct font_entry *fontptr;     /* font_entry pointer                       */
  212. struct font_entry *hfontptr=NULL;/* font_entry pointer                      */
  213. int h;                /* current horizontal position              */
  214. int hh;                /* current horizontal position in pixels    */
  215. int v;                /* current vertical position                */
  216. int vv;                /* current vertical position in pixels      */
  217. int mag;            /* magnification specified in preamble      */
  218. int nopen;            /* number of open PXL files                 */
  219. int num;            /* numerator specified in preamble          */
  220. struct font_entry *pfontptr = NULL; /* previous font_entry pointer          */
  221. struct pixel_list pixel_files[MAXOPEN+1];
  222.                                 /* list of open PXL file identifiers        */
  223. struct pixrect *screen, *display;
  224.  
  225. long postambleptr;        /* Pointer to the postamble                 */
  226. FILE *pxlfp;            /* PXL file pointer                         */
  227. char *PXLpath;            /* PXL path name for search            */
  228. struct sgttyb tty;            /* to see if program is running interactively */
  229. #define YDEFAULT 0
  230. int ydefault = YDEFAULT;
  231. int xscreen = 0, yscreen = YDEFAULT;
  232. /******************************** Unix only definitions ******************/
  233.  
  234. struct tchars tcb;        /* information about special terminal chars */
  235.  
  236. /**********************************************************/
  237.  
  238.  
  239. /**********************************************************************/
  240. /*******************************  main  *******************************/
  241. /**********************************************************************/
  242.  
  243. main(argc, argv)
  244. int argc;
  245. char *argv[];
  246.  
  247. {
  248.     struct stack_entry {  /* stack entry */
  249.     int h, v, w, x, y, z;  /* what's on stack */
  250.     };
  251.  
  252.  
  253.     int argind;             /* argument index for flags              */
  254.     int command;        /* current command                 */
  255.     long cpagep;        /* current page pointer             */
  256.     char curarea[STRSIZE];  /* current file area             */
  257.     char curext[STRSIZE];   /* current file extension             */
  258.     char curname[STRSIZE];  /* current file name             */
  259.     char filename[STRSIZE]; /* file name                 */
  260.     register int i;        /* command parameter; loop index         */
  261.     int k;            /* temporary parameter             */
  262.     char n[STRSIZE];        /* command parameter             */
  263.     int PagesLeft;          /* Number of pages left to skip          */
  264.     int PreLoad = TRUE;        /* preload the font descriptions?         */
  265.     long ppagep;        /* previous page pointer             */
  266.     int SkipEOP = FALSE;    /* input is waiting from the terminal, skip to EOP */
  267.     int SkipMode = FALSE;   /* in skip mode flag                     */
  268.     int SoundBell = FALSE;   /* if false supress bell at end of page  */
  269.     int sp;            /* stack pointer                 */
  270.     struct stack_entry stack[STACKSIZE];   /* stack             */
  271.     int t;            /* temporary                 */
  272.     char tc;            /* temporary character             */
  273.     char *tcp, *tcp1;        /* temporary character pointers         */
  274.     register struct char_entry *tcharptr;/* temporary char_entry ptr */
  275.     int val, val2;          /* temporarys to hold command information*/
  276.     int w;            /* current horizontal spacing         */
  277.     int x;            /* current horizontal spacing         */
  278.     int y;            /* current vertical spacing             */
  279.     int z;            /* current vertical spacing             */
  280.     nopen = 0;
  281.     strcpy(G_progname, argv[0]);
  282.  
  283.     if (argc < 2)  {
  284.     fprintf(stderr, "\nusage: %s -bpld +pages dvifile\n\n", G_progname);
  285.     AbortRun(1);
  286.     }
  287.  
  288.     if (ioctl(1,TIOCGETP,&tty) == -1)
  289.     G_interactive = FALSE;
  290.  
  291.    /*  get enviroment variables that allows for a path name in unix */
  292.  
  293.    if ((PXLpath=getenv("BGPXLPATH")) == NULL)
  294.     PXLpath = FONTAREA;
  295.  
  296.     argind = 1;
  297.     while (argind < argc && (*argv[argind] == '-' || *argv[argind] == '+'))
  298.     {   
  299.     tcp = argv[argind];
  300.         if (*tcp == '-')
  301.           { tcp++;
  302.         switch(*tcp){
  303.             case 'b':       /* b supresses the bell at end of page */
  304.             SoundBell = TRUE;
  305.             break;
  306.  
  307. #ifdef DEBUG
  308.         case 'd':    /* d selects Debug output */
  309.             Debug = TRUE;
  310.             break;
  311. #endif
  312.  
  313.         case 'l':    /* l prohibits logging of errors */
  314.             G_logging = -1;
  315.             break;
  316.     
  317.         case 'p':    /* p prohibits pre-font loading */
  318.             PreLoad = 0;
  319.             break;
  320.  
  321.         default:
  322.             printf("%c is not a legal flag\n", *tcp);
  323.         }
  324.     } else
  325.     { sscanf(&argv[argind][1], "%d", &PagesLeft);
  326.       SkipMode = TRUE;
  327.       PagesLeft++;
  328.         }
  329.     argind++;
  330.     }
  331.  
  332.     tcp = rindex(argv[argind], '/');
  333.     if (tcp == NULL)  {
  334.     curarea[0] = '\0';
  335.     tcp = argv[argind];
  336.     }
  337.     else  {
  338.     strncpy(curarea, argv[argind], tcp-argv[argind]+1);
  339.     tcp += 1;
  340.     }
  341.     tcp1 = index(tcp, '.');
  342.     if (tcp1 == NULL)  {
  343.     strcpy(curname, tcp);
  344.     tcp1 = index(tcp, '\0');
  345.     }
  346.     else
  347.     strncpy(curname, tcp, tcp1-tcp);
  348.     strcpy(curext, tcp1);
  349.  
  350.     strcpy(filename, curarea);
  351.     strcat(filename, curname);
  352.     if (curext[0] == '\0')
  353.     strcat(filename, ".dvi");
  354.     else
  355.     strcat(filename, curext);
  356.     if ((dvifp=BINARYOPEN(filename,"r")) == NULL)  {
  357.     fprintf(stderr,"\n");
  358.     fprintf(stderr,"%s: can't open \"%s\"\n\n", G_progname, filename);
  359.     AbortRun(1);
  360.     }
  361.  
  362.     strcpy(G_Logname, curname);
  363.     strcat(G_Logname, ".dvi-log");
  364.  
  365.     argind++;
  366.     while (argind < argc && (*argv[argind] == '-' || *argv[argind] == '+'))
  367.     {   
  368.     tcp = argv[argind];
  369.         if (*tcp == '-')
  370.           { tcp++;
  371.         switch(*tcp){
  372.             case 'b':       /* b supresses the bell at end of page */
  373.             SoundBell = TRUE;
  374.             break;
  375.  
  376. #ifdef DEBUG
  377.         case 'd':    /* d selects Debug output */
  378.             Debug = TRUE;
  379.             break;
  380. #endif
  381.  
  382.         case 'l':    /* l prohibits logging of errors */
  383.             G_logging = -1;
  384.             break;
  385.     
  386.         case 'p':    /* p prohibits pre-font loading */
  387.             PreLoad = 0;
  388.             break;
  389.  
  390.         default:
  391.             printf("%c is not a legal flag\n", *tcp);
  392.         }
  393.     } else
  394.     { sscanf(&argv[argind][1], "%d", &PagesLeft);
  395.           argind++;
  396.       SkipMode = TRUE;
  397.       PagesLeft++;
  398.         }
  399.     argind++;
  400.     }
  401.  
  402.    /* The terminal characteristics must be saved before any attempt is made */
  403.    /* to process the DVI file, so that if the latter should fail, procedure */
  404.    /* Fatal will be able to correctly restore the terminal state. */
  405.     if (G_interactive)  {
  406.     ioctl(0, TIOCGETC, &tcb);  /* get special characters */
  407.     ioctl(0, TIOCGETP, &G_intty);  /* get modes */
  408.     tty = G_intty;
  409.     tty.sg_flags |= CBREAK;
  410.     tty.sg_flags &= ~ECHO;
  411.     ioctl(0, TIOCSETP, &tty);  /* set modes */
  412.     }
  413.  
  414. #ifndef ALLOW_INTERRUPT
  415.     signal(SIGINT, SIG_IGN);  /* ignore interrupts */
  416. #endif
  417.     InitTerm();
  418. #ifndef ALLOW_INTERRUPT
  419.     signal(SIGINT, GotInterrupt);  /* catch interrupts */
  420. #endif
  421.  
  422.     if ((i = NoSignExtend(dvifp, 1)) != PRE)  {
  423.     fprintf(stderr,"\n");
  424.     Fatal("%s: PRE doesn't occur first--are you sure this is a DVI file?\n\n",
  425.     G_progname);
  426.     }
  427.  
  428.     i = SignExtend(dvifp, 1);
  429.     if (i != DVIFORMAT)  {
  430.     fprintf(stderr,"\n");
  431.     Fatal("%s: DVI format = %d, can only process DVI format %d files\n\n",
  432.     G_progname, i, DVIFORMAT);
  433.     }
  434.  
  435.     if (PreLoad)
  436.     {
  437.     ReadPostAmble();
  438.     fseek(dvifp, (long) 14, 0);
  439.     }
  440.     else
  441.     {
  442.     num = NoSignExtend(dvifp, 4);
  443.     den = NoSignExtend(dvifp, 4);
  444.     mag = NoSignExtend(dvifp, 4);
  445.     hconv = DoConv(num, den, hconvRESOLUTION);
  446.     vconv = DoConv(num, den, vconvRESOLUTION);
  447.     }
  448.     k = NoSignExtend(dvifp, 1);
  449.     GetBytes(dvifp, n, k);
  450.     while (TRUE)
  451.  
  452.     switch (command=NoSignExtend(dvifp, 1))  {
  453.  
  454.     case SET1:case SET2:case SET3:case SET4:
  455.         val = NoSignExtend(dvifp, command-SET1+1);
  456.         if (!SkipMode) SetChar(val, command);
  457.         break;
  458.  
  459.     case SET_RULE:
  460.         val = NoSignExtend(dvifp, 4);
  461.         val2 = NoSignExtend(dvifp, 4);
  462.             if (!SkipMode) SetRule(val, val2, 1);
  463.         break;
  464.  
  465.     case PUT1:case PUT2:case PUT3:case PUT4:
  466.         val = NoSignExtend(dvifp,command-PUT1+1);
  467.         if (!SkipMode) SetChar(val, command);
  468.         break;
  469.  
  470.     case PUT_RULE:
  471.         val = NoSignExtend(dvifp, 4);
  472.         val2 = NoSignExtend(dvifp, 4);
  473.             if (!SkipMode) SetRule(val, val2, 0);
  474.         break;
  475.  
  476.     case NOP:
  477.         break;
  478.  
  479.     case BOP:
  480.         cpagep = ftell(dvifp) - 1;
  481.         for (i=0; i<=9; i++)
  482.         NoSignExtend(dvifp, 4);
  483.         ppagep = NoSignExtend(dvifp, 4);
  484.  
  485.         pr_rop(display, 0, 0, display->pr_size.x, display->pr_size.y, PIX_CLR, NULL, 0, 0);
  486.         h = v = w = x = y = z = 0;
  487.         sp = 0;
  488.         fontptr = NULL;
  489.         if (PagesLeft)
  490.         { PagesLeft--;
  491.           if (PagesLeft <= 0) SkipMode = FALSE;
  492.         };
  493.         break;
  494.  
  495.     case EOP:
  496.         if (SkipEOP) { SkipMode = FALSE; SkipEOP = FALSE; }
  497.         if (G_interactive && !SkipMode)  {
  498.         t = FALSE;
  499.         while (!t)  {  /* sorry about this flow of control kludge */
  500.             t = TRUE;
  501.             tc = getchar();
  502.             if (tc==tcb.t_eofc) AllDone();
  503.             switch (tc)  {
  504.             case ' ':        /* normal case - start next page */
  505.             case '\n':
  506.             xscreen = 0; yscreen = ydefault;
  507.             break;
  508.  
  509.             case 'd':        /* move down and redisplay */
  510.             yscreen -= (YSIZE/3);
  511.             fseek(dvifp, cpagep, 0);
  512.             break;
  513.  
  514.             case 'l':        /* move left and redisplay */
  515.             xscreen += (XSIZE/3);
  516.             fseek(dvifp, cpagep, 0);
  517.             break;
  518.  
  519.             case 'p':        /* redisplay from previous page */
  520.             if (ppagep != -1)  {
  521.                 fseek(dvifp, ppagep, 0);
  522.             }
  523.             else  {
  524.                 fseek(dvifp, cpagep, 0);
  525.                 xscreen = 0; yscreen = ydefault;
  526.             }
  527.             break;
  528.  
  529.             case 'q':        /* quit */
  530.             case 'e':        /* exit */
  531.                 AllDone();
  532.                 break;
  533.  
  534.             case 'r':        /* move right and redisplay */
  535.             xscreen -= (XSIZE/3);
  536.             fseek(dvifp, cpagep, 0);
  537.             break;
  538.  
  539.             case 'u':        /* move up and redisplay */
  540.             yscreen += (YSIZE/3);
  541.             fseek(dvifp, cpagep, 0);
  542.             break;
  543.  
  544.              case '-':
  545.             /* read in val */
  546.             val = ReadInt();
  547.             while (val-- && ppagep != -1)
  548.                 { fseek(dvifp, ppagep, 0);
  549.                   NoSignExtend(dvifp, 1);
  550.                   for(i=0; i<=9; i++)
  551.                     NoSignExtend(dvifp, 4);
  552.                   cpagep = ppagep;
  553.                   ppagep = NoSignExtend(dvifp, 4);
  554.                 }
  555.             fseek(dvifp, cpagep, 0);
  556.             xscreen = 0; yscreen = ydefault;
  557.             break;
  558.  
  559. #ifdef DEBUG
  560.              case 'f':    /* fine tune y */
  561.             ydefault = ReadInt();
  562.             yscreen = ydefault;
  563.             fseek(dvifp, cpagep, 0);
  564.             break;
  565.  
  566.              case 'h': /* fine tune hconv */
  567.             hconv = DoConv(num, den, ReadInt());
  568.             fseek(dvifp, cpagep, 0);
  569.             break;
  570.  
  571.              case 'v': /* fine tune hconv */
  572.             vconv = DoConv(num, den, ReadInt());
  573.             fseek(dvifp, cpagep, 0);
  574.             break;
  575. #endif
  576.  
  577.              case '+':
  578.             /* read in val */
  579.             val = ReadInt();
  580.             SkipMode = TRUE;
  581.             PagesLeft = val;
  582.             break;
  583.  
  584.             default:
  585.             t = FALSE;
  586.             }
  587.         }
  588.         }
  589.         break;
  590.  
  591.     case PUSH:
  592.         if (sp >= STACKSIZE)
  593.         Fatal("stack overflow");
  594.         stack[sp].h = h;
  595.         stack[sp].v = v;
  596.         stack[sp].w = w;
  597.         stack[sp].x = x;
  598.         stack[sp].y = y;
  599.         stack[sp].z = z;
  600.         sp++;
  601.         break;
  602.  
  603.     case POP:
  604.         --sp;
  605.         if (sp < 0)
  606.         Fatal("stack underflow");
  607.         h = stack[sp].h;
  608.         v = stack[sp].v;
  609.         w = stack[sp].w;
  610.         x = stack[sp].x;
  611.         y = stack[sp].y;
  612.         z = stack[sp].z;
  613.         break;
  614.  
  615.     case RIGHT1:case RIGHT2:case RIGHT3:case RIGHT4:
  616.             val = SignExtend(dvifp,command-RIGHT1+1);
  617.         if (!SkipMode) MoveOver(val);
  618.         break;
  619.  
  620.     case W0:
  621.             if (!SkipMode) MoveOver(w);
  622.         break;
  623.  
  624.     case W1:case W2:case W3:case W4:
  625.         w = SignExtend(dvifp,command-W1+1);
  626.             if (!SkipMode) MoveOver(w);
  627.         break;
  628.  
  629.     case X0:
  630.             if (!SkipMode) MoveOver(x);
  631.         break;
  632.  
  633.     case X1:case X2:case X3:case X4:
  634.         x = SignExtend(dvifp,command-X1+1);
  635.         if (!SkipMode) MoveOver(x);
  636.         break;
  637.  
  638.     case DOWN1:case DOWN2:case DOWN3:case DOWN4:
  639.             val = SignExtend(dvifp,command-DOWN1+1);
  640.         if (!SkipMode) MoveDown(val);
  641.         break;
  642.  
  643.     case Y0:
  644.             if (!SkipMode) MoveDown(y);
  645.         break;
  646.  
  647.     case Y1:case Y2:case Y3:case Y4:
  648.         y = SignExtend(dvifp,command-Y1+1);
  649.             if (!SkipMode) MoveDown(y);
  650.         break;
  651.  
  652.     case Z0:
  653.             if (!SkipMode) MoveDown(z);
  654.         break;
  655.  
  656.     case Z1:case Z2:case Z3:case Z4:
  657.         z = SignExtend(dvifp,command-Z1+1);
  658.         if (!SkipMode) MoveDown(z);
  659.         break;
  660.  
  661.     case FNT1:case FNT2:case FNT3:case FNT4:
  662.         if (InputWaiting(stdin)) { SkipMode = TRUE; SkipEOP = TRUE;}
  663.             if (!SkipMode) SetFntNum(NoSignExtend(dvifp,command-FNT1+1));
  664.         break;
  665.  
  666.     case XXX1:case XXX2:case XXX3:case XXX4:
  667.         k = NoSignExtend(dvifp,command-XXX1+1);
  668.         while (k--)
  669.         NoSignExtend(dvifp, 1);
  670.         break;
  671.  
  672.     case FNT_DEF1:case FNT_DEF2:case FNT_DEF3:case FNT_DEF4:
  673.         if (PreLoad)
  674.         {
  675.         SkipFontDef (NoSignExtend(dvifp, command-FNT_DEF1+1));
  676.         }
  677.         else
  678.         {
  679.         ReadFontDef (NoSignExtend(dvifp, command-FNT_DEF1+1));
  680.         }
  681.         break;
  682.  
  683.     case PRE:
  684.         Fatal("PRE occurs within file");
  685.         break;
  686.  
  687.     case POST:
  688.         if (SkipMode) fseek(dvifp, cpagep, 0);
  689.                else { fseek(dvifp, (long) -2, 1); }
  690.         SkipMode = FALSE;
  691.         PagesLeft = 0;
  692.         break;
  693.  
  694.     case POST_POST:
  695.          Fatal("POST_POST with no preceding POST");
  696.         break;
  697.  
  698.     default:
  699.         if (command >= FONT_00 && command <= FONT_63)
  700.         {if (InputWaiting(stdin)) { SkipMode = TRUE; SkipEOP = TRUE;}
  701.          if (!SkipMode) SetFntNum(command - FONT_00);}
  702.         else if (command >= SETC_000 && command <= SETC_127)
  703.         {if (!SkipMode) SetChar(command - SETC_000, command);}
  704.         else
  705.         Fatal("%d is an undefined command", command);
  706.         break;
  707.  
  708.     }
  709.  
  710. }
  711.  
  712. /*-->AbortRun*/
  713. /**********************************************************************/
  714. /***************************  AbortRun  *******************************/
  715. /**********************************************************************/
  716.  
  717. void
  718. AbortRun(code)
  719. int code;
  720. {
  721.     exit(code);
  722. }
  723.  
  724.  
  725. /*-->ActualFactor*/
  726. /**********************************************************************/
  727. /**************************  ActualFactor  ****************************/
  728. /**********************************************************************/
  729.  
  730. float        /* compute the actual size factor given the approximation */
  731. ActualFactor(unmodsize)
  732. int unmodsize;  /* actually factor * 1000 */
  733. {
  734.     float realsize;    /* the actual magnification factor */
  735.  
  736.     realsize = (float)unmodsize / 1000.0;
  737.     /* a real hack to correct for rounding in some cases--rkf */
  738.     if(unmodsize==1095) realsize = 1.095445;    /*stephalf*/
  739.     else if(unmodsize==1315) realsize=1.314534;    /*stepihalf*/
  740.     else if(unmodsize==2074) realsize=2.0736;    /*stepiv*/
  741.     else if(unmodsize==2488) realsize=2.48832;  /*stepv*/
  742.     else if(unmodsize==2986) realsize=2.985984;    /*stepiv*/
  743.     /* the remaining magnification steps are represented with sufficient
  744.        accuracy already */
  745.     return(realsize);
  746. }
  747.  
  748.  
  749. /*-->AllDone*/
  750. /**********************************************************************/
  751. /****************************** AllDone  ******************************/
  752. /**********************************************************************/
  753.  
  754. void
  755. AllDone()
  756. {
  757.     char t;
  758.  
  759.     ResetTerm();
  760.     if (G_errenc && G_logging == 1)  {
  761.     fseek(G_logfp, 0, 0);
  762.     while ((t=getc(G_logfp)) != EOF)
  763.         putchar(t);
  764.     }
  765.     if (G_logging == 1) printf("Log file created\n");
  766.     AbortRun(G_errenc);
  767. }
  768.  
  769. /*-->DoConv*/
  770.  
  771. int DoConv(num, den, convResolution)
  772. {
  773.     register float conv;
  774.     conv = ((float)num/(float)den) * 
  775. #ifdef USEGLOBALMAG
  776. /*    ActualFactor(mag) * why was this in as Actual Factor?  jls */
  777.     ((float) mag/1000.0) *
  778. #endif
  779.     ((float)convResolution/254000.0);
  780.     return((int) (1.0 / conv + 0.5));
  781. }
  782.  
  783. /*-->Fatal*/
  784. /**********************************************************************/
  785. /******************************  Fatal  *******************************/
  786. /**********************************************************************/
  787.  
  788. void
  789. Fatal(fmt, args)/* issue a fatal error message */
  790. char *fmt;    /* format */
  791. char *args;    /* arguments */
  792.  
  793. {
  794.     if (G_logging == 1)
  795.     {
  796.     fprintf(G_logfp, "%s: FATAL--", G_progname);
  797.     _doprnt(fmt, &args, G_logfp);
  798.     fprintf(G_logfp, "\n");
  799.     }
  800.  
  801.     ResetTerm();
  802.     fprintf(stderr,"\n");
  803.     fprintf(stderr, "%s: FATAL--", G_progname);
  804.     _doprnt(fmt, &args, stderr);
  805.     fprintf(stderr, "\n\n");
  806.     if (G_logging == 1) printf("Log file created\n");
  807.     AbortRun(1);
  808. }
  809.  
  810.  
  811. /*-->FindPostAmblePtr*/
  812. /**********************************************************************/
  813. /************************  FindPostAmblePtr  **************************/
  814. /**********************************************************************/
  815.  
  816. void
  817. FindPostAmblePtr(postambleptr)
  818. long    *postambleptr;
  819.  
  820. /* this routine will move to the end of the file and find the start
  821.     of the postamble */
  822.  
  823. {
  824.     int     i;
  825.  
  826.     fseek (dvifp, (long) 0, 2);   /* goto end of file */
  827.     *postambleptr = ftell (dvifp) - 4;
  828.     fseek (dvifp, *postambleptr, 0);
  829.  
  830.     while (TRUE) {
  831.     fseek (dvifp, --(*postambleptr), 0);
  832.     if (((i = NoSignExtend(dvifp, 1)) != 223) &&
  833.         (i != DVIFORMAT))
  834.         Fatal ("Bad end of DVI file");
  835.     if (i == DVIFORMAT)
  836.         break;
  837.     }
  838.     fseek (dvifp, (*postambleptr) - 4, 0);
  839.     (*postambleptr) = NoSignExtend(dvifp, 4);
  840.     fseek (dvifp, *postambleptr, 0);
  841. }
  842.  
  843.  
  844. /*-->GetBytes*/
  845. /**********************************************************************/
  846. /*****************************  GetBytes  *****************************/
  847. /**********************************************************************/
  848.  
  849. void
  850. GetBytes(fp, cp, n)    /* get n bytes from file fp */
  851. register FILE *fp;    /* file pointer     */
  852. register char *cp;    /* character pointer */
  853. register int n;        /* number of bytes  */
  854.  
  855. {
  856.     while (n--)
  857.     *cp++ = getc(fp);
  858. }
  859.  
  860.  
  861. /*-->GetFontDef*/
  862. /**********************************************************************/
  863. /**************************** GetFontDef  *****************************/
  864. /**********************************************************************/
  865.  
  866. void
  867. GetFontDef()
  868.  
  869. /***********************************************************************
  870.    Read the font  definitions as they  are in the  postamble of the  DVI
  871.    file.  Note that the font directory  is not yet loaded.  In order  to
  872.    adapt ourselves to the existing "verser" the following font paramters
  873.    are  copied     onto  output    fontno  (4   bytes),  chksum,    fontmag,
  874.    fontnamelength (1 byte), fontname.  At the end, a -1 is put onto  the
  875.    file.
  876. ***********************************************************************/
  877.  
  878. {
  879.     char    str[50], *calloc ();
  880.     unsigned char   byte;
  881.     int     i, fnamelen;
  882.  
  883.     while (((byte = NoSignExtend(dvifp, 1)) >= FNT_DEF1) &&
  884.     (byte <= FNT_DEF4)) {
  885.     switch (byte) {
  886.     case FNT_DEF1:
  887.         ReadFontDef (NoSignExtend(dvifp, 1));
  888.         break;
  889.     case FNT_DEF2:
  890.         ReadFontDef (NoSignExtend(dvifp, 2));
  891.         break;
  892.     case FNT_DEF3:
  893.         ReadFontDef (NoSignExtend(dvifp, 3));
  894.         break;
  895.     case FNT_DEF4:
  896.         ReadFontDef (NoSignExtend(dvifp, 4));
  897.         break;
  898.     default:
  899.         Fatal ("Bad byte value in font defs");
  900.         break;
  901.     }
  902.     }
  903.     if (byte != POST_POST)
  904.     Fatal ("POST_POST missing after fontdefs");
  905. }
  906.  
  907.  
  908. /*-->GotInterrupt*/
  909. /**********************************************************************/
  910. /***************************  GotInterrupt  ***************************/
  911. /**********************************************************************/
  912.  
  913. void
  914. GotInterrupt(sig)   /* don't leave terminal in a weird state */
  915. int sig;
  916.  
  917. {
  918.     ResetTerm();
  919.     if (G_logging == 1) printf("Log file created\n");
  920.     AbortRun(G_errenc);
  921. }
  922.  
  923.  
  924. /*-->InitTerm*/
  925. /**********************************************************************/
  926. /*****************************  InitTerm  *****************************/
  927. /**********************************************************************/
  928.  
  929. void
  930. InitTerm()    /* initialize terminal */
  931.  
  932. {
  933.     screen = pr_open("/dev/bw0");
  934.     if (screen == NULL) {
  935.     perror("pixel: ");
  936.     exit(1);
  937.     }
  938.     display = screen;
  939. }
  940.  
  941. /*-->InputWaiting*/
  942. /**********************************************************************/
  943. /************************* InputWaiting *******************************/
  944. /**********************************************************************/
  945.  
  946. int
  947. InputWaiting(fp)
  948. FILE *fp;
  949.  
  950. /*   this routine returns TRUE if there is input waiting to be read
  951.     and FALSE otherwise.  note that it may take time to realize
  952.     that there is input waiting so the routine may occasionaly
  953.     be wrong.   */
  954. {
  955.     long retval;
  956.  
  957.     if (fp->_cnt != 0) return(TRUE);
  958.     ioctl(fileno(fp), FIONREAD, &retval);
  959.     return((int)retval);
  960. }
  961.  
  962.  
  963. /*-->LoadRast*/
  964. /**********************************************************************/
  965. /*****************************  LoadRast  *****************************/
  966. /**********************************************************************/
  967.  
  968. void
  969. LoadRast(pxlfp, w, h)    /* load raster pattern into BitGraph */
  970. FILE *pxlfp;        /* PXL file pointer       */
  971. int w;            /* width of raster in pixels */
  972. int h;            /* height of raster in pixels */
  973.  
  974. {
  975.     register int ew;  /* extra word at end of row? */
  976.     register int t;   /* temporary          */
  977.     register int ww;  /* width of raster in words */
  978.  
  979.     ww = (w+15) / 16;
  980.     ew = ww & 1;
  981.     while (h--)  {
  982.     t = ww;
  983.     while (t--)
  984.         PutOut(NoSignExtend(pxlfp, 2));
  985.     if (ew)
  986.         NoSignExtend(pxlfp, 2);
  987.     }
  988. }
  989.  
  990.  
  991. /*-->MoveDown*/
  992. /**********************************************************************/
  993. /****************************  MoveDown  ******************************/
  994. /**********************************************************************/
  995.  
  996. void
  997. MoveDown(a)
  998. int a;
  999. {
  1000.     v += a;
  1001. }
  1002.  
  1003.  
  1004. /*-->MoveOver*/
  1005. /**********************************************************************/
  1006. /****************************  MoveOver  ******************************/
  1007. /**********************************************************************/
  1008.  
  1009. void
  1010. MoveOver(b)
  1011. int b;
  1012. {
  1013.     h += b;
  1014. }
  1015.  
  1016.  
  1017. /*-->OpenFontFile*/
  1018. /**********************************************************************/
  1019. /************************** OpenFontFile  *****************************/
  1020. /**********************************************************************/
  1021.  
  1022. void
  1023. OpenFontFile()
  1024. /***********************************************************************
  1025.     The original version of this dvi driver reopened the font file  each
  1026.     time the font changed, resulting in an enormous number of relatively
  1027.     expensive file  openings.   This version  keeps  a cache  of  up  to
  1028.     MAXOPEN open files,  so that when  a font change  is made, the  file
  1029.     pointer, pxlfp, can  usually be  updated from the  cache.  When  the
  1030.     file is not found in  the cache, it must  be opened.  In this  case,
  1031.     the next empty slot  in the cache  is assigned, or  if the cache  is
  1032.     full, the least used font file is closed and its slot reassigned for
  1033.     the new file.  Identification of the least used file is based on the
  1034.     counts of the number  of times each file  has been "opened" by  this
  1035.     routine.  On return, the file pointer is always repositioned to  the
  1036.     beginning of the file.
  1037.  
  1038. ***********************************************************************/
  1039. {
  1040.     register int i,least_used,current;
  1041.  
  1042. #ifdef DEBUG
  1043.     if (Debug) printf("Open Font file\n");
  1044. #endif
  1045.     if (pfontptr == fontptr)
  1046.         return;                 /* we need not have been called */
  1047.  
  1048.     for (current = 1;
  1049.     (current <= nopen) &&
  1050.         (pixel_files[current].pixel_file_id != fontptr->font_file_id);
  1051.     ++current)
  1052.     ;                       /* try to find file in open list */
  1053.  
  1054.     if (current <= nopen)       /* file already open */
  1055.     {
  1056.     pxlfp = pixel_files[current].pixel_file_id;
  1057.     fseek(pxlfp,0,0);    /* reposition to start of file */
  1058.     }
  1059.     else                        /* file not in open list */
  1060.     {
  1061.         if (nopen < MAXOPEN)    /* just add it to list */
  1062.             current = ++nopen;
  1063.     else                    /* list full -- find least used file, */
  1064.     {                       /* close it, and reuse slot for new file */
  1065.         least_used = 1;
  1066.             for (i = 2; i <= MAXOPEN; ++i)
  1067.             if (pixel_files[least_used].use_count >
  1068.                     pixel_files[i].use_count)
  1069.             least_used = i;
  1070.         fclose(pixel_files[least_used].pixel_file_id);
  1071.         current = least_used;
  1072.         }
  1073.         if ((pxlfp=BINARYOPEN(fontptr->name,"r")) == NULL)
  1074.         Fatal("PXL file \"%s\" could not be opened; %d PXL files are open",
  1075.         fontptr->name,nopen);
  1076.     pixel_files[current].pixel_file_id = pxlfp;
  1077.     pixel_files[current].use_count = 0;
  1078.     }
  1079.     pfontptr = fontptr;            /* make previous = current font */
  1080.     fontptr->font_file_id = pxlfp;    /* set file identifier */
  1081.     pixel_files[current].use_count++;    /* update reference count */
  1082. }
  1083.  
  1084.  
  1085. /*-->PixRound*/
  1086. /**********************************************************************/
  1087. /*****************************  PixRound  *****************************/
  1088. /**********************************************************************/
  1089.  
  1090. int
  1091. PixRound(x, conv)    /* return rounded number of pixels */
  1092. register int x;        /* in DVI units     */
  1093. int conv;        /* conversion factor */
  1094. {
  1095.     return((int)((x + (conv >> 1)) / conv));
  1096. }
  1097.  
  1098.  
  1099. /*-->PutOut*/
  1100. /**********************************************************************/
  1101. /******************************  PutOut  ******************************/
  1102. /**********************************************************************/
  1103.  
  1104. void
  1105. PutOut(x)    /* put a 16-bit raster pattern to the BitGraph */
  1106. register int x; /* number to put out */
  1107.  
  1108. {
  1109.     int negative;               /* was x negative? */
  1110.     register int part1, part2, part3;  /* parts of number */
  1111.  
  1112.     negative = FALSE;
  1113.     if (x < 0)  {
  1114.     negative = TRUE;
  1115.     x = -x;
  1116.     }
  1117.     part1 = (x & 0xfc00) >> 10;
  1118.     part2 = (x & 0x03f0) >>  4;
  1119.     part3 = (x & 0x000f);
  1120.     if (part1)  {
  1121.     putchar(0100+part1);
  1122.     putchar(0100+part2);
  1123.     }
  1124.     else
  1125.     if (part2)
  1126.         putchar(0100+part2);
  1127.     if (negative)
  1128.     putchar(040+part3);
  1129.     else
  1130.     putchar(060 + part3);
  1131. }
  1132.  
  1133.  
  1134. /*-->ReadFontDef*/
  1135. /**********************************************************************/
  1136. /****************************  ReadFontDef  ***************************/
  1137. /**********************************************************************/
  1138.  
  1139. int
  1140. ReadFontDef(k)
  1141. int k;
  1142. {
  1143.     int t, i;
  1144.     register struct font_entry *tfontptr;    /* temporary font_entry pointer   */
  1145.     register struct char_entry *tcharptr;/* temporary char_entry pointer  */
  1146.     char *direct, *tcp, *tcp1;
  1147.     int found;
  1148.     char curarea[STRSIZE];
  1149.  
  1150.     if ((tfontptr = NEW(struct font_entry)) == NULL)
  1151.     Fatal("can't malloc space for font_entry");
  1152.     tfontptr->next = hfontptr;
  1153.     fontptr = hfontptr = tfontptr;
  1154.  
  1155.     tfontptr->k = k;
  1156.     tfontptr->c = NoSignExtend(dvifp, 4); /* checksum */
  1157.     tfontptr->s = NoSignExtend(dvifp, 4); /* space size */
  1158.     tfontptr->d = NoSignExtend(dvifp, 4); /* design size */
  1159.     tfontptr->a = NoSignExtend(dvifp, 1); /* area length for font name */
  1160.     tfontptr->l = NoSignExtend(dvifp, 1); /* device length */
  1161.     GetBytes(dvifp, tfontptr->n, tfontptr->a+tfontptr->l);
  1162.     tfontptr->n[tfontptr->a+tfontptr->l] = '\0';
  1163.     tfontptr->font_space = tfontptr->s/6; /* never used */
  1164.     tfontptr->font_mag = (int)((ActualFactor((int)(((float)tfontptr->s/
  1165.                 (float)tfontptr->d)*1000.0 + 0.5)) * 
  1166. #ifdef USEGLOBALMAG
  1167.             ActualFactor(mag) *
  1168. #endif
  1169.             (float)RESOLUTION * 5.0) + 0.5);
  1170.     if (tfontptr->a != 0) {
  1171.     sprintf(tfontptr->name, "%s.%dpxl", tfontptr->n, tfontptr->font_mag);
  1172.     } else {
  1173.     direct = PXLpath;
  1174.     found = FALSE;
  1175.         do { 
  1176.         tcp = index(direct, ':');
  1177.         if (tcp == NULL) tcp = strlen(direct) + direct;
  1178.         strncpy(curarea, direct, tcp-direct);
  1179.         tcp1 = curarea + (tcp - direct);
  1180.         *tcp1++ = '/';
  1181.         *tcp1++ = '\0';
  1182.  
  1183.         sprintf(tfontptr->name, "%s%s.%dpxl", curarea, tfontptr->n, tfontptr->font_mag);
  1184.         found = (access(tfontptr->name, READ) == 0);
  1185.         if (*tcp) direct = tcp + 1; else direct = tcp;
  1186.     } while ( !found && *direct != '\0');
  1187.     }
  1188.     if (tfontptr != pfontptr)
  1189.     OpenFontFile();
  1190.     if ((t = NoSignExtend(pxlfp, 4)) != PXLID)
  1191.     Fatal("PXL ID = %d, can only process PXL ID = %d files",
  1192.           t, PXLID);
  1193.     fseek(pxlfp, -20, 2);
  1194.     t = NoSignExtend(pxlfp, 4);
  1195.     if ((tfontptr->c != 0) && (t != 0) && (tfontptr->c != t))
  1196.     Warning("font = \"%s\",\n-->font checksum = %d,\n-->dvi checksum = %d",
  1197.             tfontptr->name, tfontptr->c, t);
  1198.     tfontptr->magnification = NoSignExtend(pxlfp, 4);
  1199.     tfontptr->designsize = NoSignExtend(pxlfp, 4);
  1200.  
  1201.     fseek(pxlfp, NoSignExtend(pxlfp, 4) * 4, 0);
  1202.  
  1203.     for (i = FIRSTPXLCHAR; i <= LASTPXLCHAR; i++) {
  1204.     tcharptr = &(tfontptr->ch[i]);
  1205.     tcharptr->width = NoSignExtend(pxlfp, 2);
  1206.     tcharptr->height = NoSignExtend(pxlfp, 2);
  1207.     tcharptr->xOffset= SignExtend(pxlfp, 2);
  1208.     tcharptr->yOffset = SignExtend(pxlfp, 2);
  1209.     tcharptr->where.isloaded = FALSE;
  1210.     tcharptr->where.address.fileOffset = NoSignExtend(pxlfp, 4) * 4;
  1211.     tcharptr->tfmw = ((float)NoSignExtend(pxlfp, 4)*(float)tfontptr->s) /
  1212.         (float)(1<<20);
  1213.     }
  1214. }
  1215.  
  1216.  
  1217. /**********************************************************************/
  1218. /****************************  ReadInt  *******************************/
  1219. /**********************************************************************/
  1220.  
  1221. /*  this routine is used to read in an integer from the stdin stream.
  1222.     This routine is necessary since the terminal is running in
  1223.     CBREAK mode and therefore will not do editing of the input
  1224.     stream for one. */
  1225.  
  1226. ReadInt()
  1227. {
  1228.    int value = 0;
  1229.    int byte;
  1230.  
  1231.    while ((byte = getchar()) != /* tcb.t_brkc */ 10)
  1232.     { if (byte >= 48 /* "0" */ && byte <= 57 /* "9" */)
  1233.           value = value * 10 + byte - 48;
  1234.       if (byte == tty.sg_erase) value = value / 10;
  1235.         }
  1236.    return(value);
  1237. }
  1238.           
  1239.  
  1240. /*-->ReadPostAmble*/
  1241. /**********************************************************************/
  1242. /**************************  ReadPostAmble  ***************************/
  1243. /**********************************************************************/
  1244.  
  1245. void
  1246. ReadPostAmble()
  1247. /***********************************************************************
  1248.     This  routine  is  used  to  read  in  the  postamble  values.    It
  1249.     initializes the magnification and checks  the stack height prior  to
  1250.     starting printing the document.
  1251. ***********************************************************************/
  1252. {
  1253.     FindPostAmblePtr (&postambleptr);
  1254.     if (NoSignExtend(dvifp, 1) != POST)
  1255.     Fatal ("POST missing at head of postamble");
  1256. #ifdef DEBUG
  1257.     if (Debug) fprintf (stderr, "got POST command\n");
  1258. #endif
  1259.     /*      lastpageptr = */ NoSignExtend(dvifp, 4);
  1260.     num = NoSignExtend(dvifp, 4);
  1261.     den = NoSignExtend(dvifp, 4);
  1262.     mag = NoSignExtend(dvifp, 4);
  1263.     hconv = DoConv(num, den, hconvRESOLUTION);
  1264.     vconv = DoConv(num, den, vconvRESOLUTION);
  1265.  
  1266.     NoSignExtend(dvifp, 4);    /* height-plus-depth of tallest page */
  1267.     NoSignExtend(dvifp, 4);    /* width of widest page */
  1268.     if (NoSignExtend(dvifp, 2) >= STACKSIZE)
  1269.     Fatal ("Stack size is too small");
  1270.     NoSignExtend(dvifp, 2);    /* this reads the number of pages in */
  1271.     /* the DVI file */
  1272. #ifdef DEBUG
  1273.     if (Debug) fprintf (stderr, "now reading font defs");
  1274. #endif
  1275.     GetFontDef ();
  1276. }
  1277.  
  1278.  
  1279. /*-->ResetTerm*/
  1280. /**********************************************************************/
  1281. /****************************  ResetTerm  *****************************/
  1282. /**********************************************************************/
  1283.  
  1284. void
  1285. ResetTerm()   /* Reset Terminal */
  1286. {
  1287.     if (G_interactive)
  1288.     ioctl(0, TIOCSETP, &G_intty);  /* restore modes */
  1289. }
  1290.  
  1291. /*-->SetChar*/
  1292. /**********************************************************************/
  1293. /*****************************  SetChar  ******************************/
  1294. /**********************************************************************/
  1295.  
  1296. int buffer[8];
  1297.  
  1298. LoadAChar(ptr)
  1299. register struct char_entry *ptr;
  1300. {
  1301.     register struct pixrect *pr;
  1302.     register int nshorts, i, col, nints;
  1303.     register short *dp, *sp;
  1304.     if (ptr->where.address.fileOffset == 0) {
  1305.     ptr->where.address.pixrectptr = NULL;
  1306.     return;
  1307.     }
  1308.     OpenFontFile();
  1309.     fseek(pxlfp, ptr->where.address.fileOffset, 0);
  1310.     nshorts = (ptr->width + 15) >> 4;
  1311.     pr = mem_create(ptr->width, ptr->height, 1);
  1312.     nints = (nshorts + 1) >> 1;
  1313.     dp = ((struct mpr_data *)pr->pr_data)->md_image;
  1314.     for (col = 0; col < ptr->height; col++) {
  1315.     fread(buffer, 4, nints, pxlfp);
  1316.     sp = (short *) &buffer[0];
  1317.     for (i = nshorts; i > 0; i--) *dp++ = *sp++;
  1318.     }
  1319.     ptr->where.address.pixrectptr = pr;
  1320.     ptr->where.isloaded = TRUE;
  1321. }
  1322.  
  1323. void
  1324. SetChar(c, command)
  1325. int c, command;
  1326. {
  1327.     register struct char_entry *ptr;  /* temporary char_entry pointer */
  1328.     int k;
  1329.  
  1330.     ptr = &(fontptr->ch[c]);
  1331.     hh = PixRound(h, hconv);
  1332.     vv = PixRound(v, vconv);
  1333.     if (!ptr->where.isloaded) LoadAChar(ptr);
  1334.     pr_rop(display, hh-ptr->xOffset-xscreen, vv-ptr->yOffset-yscreen, ptr->width, ptr->height, PIX_SRC | PIX_DST, ptr->where.address.pixrectptr, 0, 0);
  1335.     if (command <= SET4) h += ptr->tfmw;
  1336. }
  1337.  
  1338.  
  1339. /*-->SetFntNum*/
  1340. /**********************************************************************/
  1341. /****************************  SetFntNum  *****************************/
  1342. /**********************************************************************/
  1343.  
  1344. void
  1345. SetFntNum(k)
  1346. int k;
  1347.  
  1348. /*  this routine is used to specify the font to be used in printing future
  1349.     characters */
  1350.  
  1351. {
  1352.     fontptr = hfontptr;
  1353.     while ((fontptr!=NULL) && (fontptr->k!=k))
  1354.     fontptr = fontptr->next;
  1355.     if (fontptr == NULL)
  1356.     Fatal("font %d undefined", k);
  1357. }
  1358.  
  1359.  
  1360. /*-->SetRule*/
  1361. /**********************************************************************/
  1362. /*****************************  SetRule  ******************************/
  1363. /**********************************************************************/
  1364.  
  1365. void
  1366. SetRule(a, b, Set)
  1367. int a, b;
  1368. BOOLEAN Set;
  1369.  
  1370. {        /*     this routine will draw a rule on the screen */
  1371.     int ehh, evv;
  1372.     hh = PixRound(h, hconv);
  1373.     vv = PixRound(v-a, vconv);
  1374.     ehh = PixRound(h + b, hconv);
  1375.     evv = PixRound(v, vconv);
  1376.     if (hh == ehh) ehh++;
  1377.     if (vv == evv) vv--;
  1378.     if ((a > 0) && (b > 0))
  1379.         pr_rop(display, hh-xscreen, vv-yscreen, ehh-hh, evv-vv, PIX_SET, NULL, 0, 0);
  1380.     if (Set) {
  1381.     h += b;
  1382. /*        v += a; */
  1383.     }
  1384. }
  1385.  
  1386. /*-->SkipFontDef*/
  1387. /**********************************************************************/
  1388. /****************************  SkipFontDef  ***************************/
  1389. /**********************************************************************/
  1390.  
  1391. void
  1392. SkipFontDef(k)
  1393. int k;
  1394. {
  1395.     int a, l;
  1396.     char n[STRSIZE];
  1397.  
  1398.     NoSignExtend(dvifp, 4);
  1399.     NoSignExtend(dvifp, 4);
  1400.     NoSignExtend(dvifp, 4);
  1401.     a = NoSignExtend(dvifp, 1);
  1402.     l = NoSignExtend(dvifp, 1);
  1403.     GetBytes(dvifp, n, a+l);
  1404. }
  1405.  
  1406.  
  1407. /*-->Warning*/
  1408. /**********************************************************************/
  1409. /*****************************  Warning  ******************************/
  1410. /**********************************************************************/
  1411.  
  1412. void
  1413. Warning(fmt, args)  /* issue a warning */
  1414. char *fmt;    /* format   */
  1415. char *args;    /* arguments */
  1416. {
  1417.     if (G_logging == 0)
  1418.     {
  1419.     G_logfp=fopen(G_Logname,"w+");
  1420.     G_logging = 1;
  1421.     if (G_logfp == NULL) G_logging = -1;
  1422.     }
  1423.  
  1424.     G_errenc = TRUE;
  1425.     if (G_logging == 1)
  1426.     {
  1427.     _doprnt(fmt, &args, G_logfp);
  1428.     fprintf(G_logfp,"\n");
  1429.     }
  1430. }
  1431.